package com.dingwen.treasure.business.juc;


import java.util.concurrent.TimeUnit;

/**
 * 　DeadLockDemo: 死锁案例
 * 　@author dingwen
 * 　@date 2022/7/1
 *
 */
public class DeadLockDemo {
    public static void main(String[] args) {
         Object o1 = new Object();
         Object o2= new Object();

        new Thread(() -> {
            synchronized (o1){
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("持有o1的锁想获得o2的锁");
                synchronized (o2) {

                }
            }
        }).start();
        new Thread(() -> {
            synchronized (o2){
                System.out.println("持有o2的锁想获得o1的锁");
                synchronized (o1) {

                }
            }
        }).start();

    }
}
